<?php

namespace app\miniprograms\controller;

use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
use think\App;;
use think\Db;

/**
 * 地区管理
 * Class Area
 * @package app\admin\controller
 * @author liuda <1576283429@qq.com>       // Db::table('area')->alias('A')->join('system_user U','A.create_by_id = U.id','LEFT')->select();

 * @date
 */
class Area extends BasicAdmin
{
    public $table = 'area';
    /**
     * 地区管理列表
     */
    public function index(){

        $this->title = '地区列表管理';

        return parent::_list(Db::table('area')->alias('A')->join('system_user U','A.create_by_id = U.id','LEFT')->field('A.id, A.area_name,A.create_time,U.username')->where('A.is_deleted = 0')->order('A.id desc'));

    }

    /**
     * 添加地区
     * @return array|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\Exception
     */
    public function add()
    {
        return $this->_form($this->table, 'form');
    }


    /**
     * 表单数据默认处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function _form_filter(&$data)
    {
        if ($this->request->isPost()) {
            $data['area_name'] = $this->request->post('area_name');
            $data['create_time'] = time();
            $data['create_by_id'] = session('user.id');
            $data['is_del'] =0;
        } else {

        }
    }


   /*
    * 编辑地区
    */
    public function edit()
    {
        return $this->_form($this->table, 'form');
    }


    /**
     * 删除地区
     */
    public function del(){
        if (DataService::update($this->table)) {
            $this->success("地区删除成功！", '');
        }
        $this->error("地区删除失败，请稍候再试！");
    }



}